2024-08-24
This shows the Pokemon with the highest defense and hp in the top-right corner of the plot.
Let’s suppose we wanted to flip that and see the Pokemon with the highest defense and lowest hp in the top-right corner.
Let’s find out the name of the Pokemon with low hp and high defense:
pokemon |>
ggplot() +
geom_point(aes(x = defense, y = hp)) +
scale_y_reverse() +
# repel the text labels:
geom_text_repel(aes(x = defense, y = hp, label = name)) +
# limit the x-axis to `defense` of 150 or more:
# `NA` ("Not Available") is a missing value indicator.
# We use it here to say that there is no upper limit on the x-axis.
scale_x_continuous(limits = c(150, NA))n.breakstype_1 of the Pokemon in relation to their defense and hp.filter for first generation Pokemon for simplicity.type_1Let’s use colors associated with 🔥, 🍃, and 💧 Pokemon:
pokemon |>
filter(generation == 1) |>
# filter for just a few types
filter(type_1 %in% c("Water", "Fire", "Grass")) |>
ggplot() +
geom_point(aes(x = defense, y = hp, color = type_1)) +
geom_text_repel(aes(x = defense, y = hp, label = name)) +
# use the `type_1` colors instead of the default:
scale_color_manual(values = c(
Water = "blue",
Fire = "red",
Grass = "green"
))scale_colorstat_total roughly represents how powerful a Pokemon is, which makes it obvious how good Mewtwo is.
pokemon |>
filter(generation == 1) |>
ggplot() +
# color the points by `stat_total` instead of `type1`:
geom_point(aes(x = defense, y = hp, color = stat_total)) +
# use the `viridis` color palette instead of the default:
scale_color_viridis_c() +
geom_text_repel(aes(x = defense, y = hp, label = name))We could also use size to represent stat_total, which makes it obvious how bad Magikarp is!
pokemon |>
filter(generation == 1) |>
# just water pokemon
filter(type_1 == "Water") |>
ggplot() +
geom_point(aes(x = defense, y = hp, size = stat_total)) +
# this scales the difference in size between points:
scale_size_continuous(range = c(1, 10)) +
geom_text_repel(aes(x = defense, y = hp, label = name))https://fredner.org